package com.example.ksnacosprovider.Controller;

import com.alibaba.fastjson.JSON;
import com.example.ksnacosprovider.Service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pojo.Customer;
import tools.Page;

import java.util.List;

@RestController
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    //增加客户信息
    @RequestMapping(value = "/InsertCustomer")
    public boolean InsertCustomer(@RequestBody Customer customer){
        return customerService.InsertCustomer(customer);
    }

    //删除客户信息
    @RequestMapping(value = "/DelCustomer")
    public boolean DelCustomer(@RequestParam("id") int id){
        return customerService.DelCustomer(id);
    }

    //修改客户信息
    @RequestMapping(value = "/UpdateCustomer")
    public boolean UpdateCustomer(@RequestBody Customer customer){
        return customerService.UpdateCustomer(customer);
    }

    //分页查询客户信息
    @RequestMapping(value = "/SelCustomer")
    public String SelCustomer(@RequestParam("customerNumber") String customerNumber,
                              @RequestParam("customerName") String customerName,
                              @RequestParam("pageno") Integer pageno){
        Page page = new Page();
        if(pageno >0){
            page.setPageNo(pageno);
        }
        int i = customerService.SelectTotle(customerNumber,customerName);
        page.setTotle(i);
        return JSON.toJSONString(customerService.SelCustomer(customerNumber,customerName,page));
    }


}
